//
//  MPCommentViewController.m
//  SearchPeople
//
//  Created by zk on 16/5/6.
//
//

#import "MPCommentViewController.h"
#import "MPSettingsManager.h"
#import "MPDocumentHttpClient.h"
#import <SVProgressHUD.h>

@interface MPCommentViewController ()
@property (weak, nonatomic) IBOutlet UITextView *CommentTextView;

@end

@implementation MPCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self Attribute];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - private

- (void)Attribute
{
    self.view.backgroundColor = [UIColor colorWithRed:241 / 255.0 green:241 / 255.0 blue:241 / 255.0  alpha:1];
    self.CommentTextView.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    UIBarButtonItem *buttonitem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(RightBarButtonClick)];
    self.navigationItem.rightBarButtonItem = buttonitem;
}

#pragma mark - IBAction

- (void)RightBarButtonClick
{
    NSDictionary *userDic = [[MPSettingsManager getInstance].userDefault objectForKey:@"user"];
    NSString *userid = [userDic objectForKey:@"user_id"];
    if (!userid) {
        [SVProgressHUD showErrorWithStatus:@"请登录"];
    } else {
        if (self.CommentTextView.text.length > 0) {
            [[MPDocumentHttpClient shareInstance] CommentWithUserID:userid WithContent:self.CommentTextView.text WithMPID:self.MPID WithSuccessBlock:^(MPRequest *request, MPResponse *response) {
                [self.navigationController popViewControllerAnimated:YES];
            } WithFailedBlock:^(MPRequest *request, MPResponse *response) {
                [SVProgressHUD showErrorWithStatus:REQUEST_FAILE];
            }];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
